package 刷题10月.位运算;
import java.util.*;
// https://www.nowcoder.com/practice/2cc32b88fff94d7e8fd458b8c7b25ec1?tpId=117&&tqId=37836&rp=1&ru=/activity/oj&qru=/ta/job-code-high/question-ranking
public class NC112进制转换1001 {
    public class Solution {
        public String solve (int M, int N) {
            String t = "0123456789ABCDEF";
            if(M==0){return "0";}
            StringBuffer ans =new StringBuffer();//此方法针对的是io流
            boolean fu = false;//记录一下M是不是负数
            if(M<0){fu = true;M=-M;}//如果是负数，换成正数计算，最后再加上符号位
            while(M!=0)
            {
                ans.append(t.charAt(M%N));
                M/=N;
            }
            if(fu){ans.append('-');}
            return ans.reverse().toString();
        }
    }
}
